<template>
  <div>
    <a-modal
      centered
      :title="title"
      :width="width"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭">

      <a-spin :spinning="confirmLoading">
        <j-form-container >
          <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
            <a-row>
              <a-col :span="24">
                <a-form-model-item label="验收时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
                  <j-date placeholder="请选择验收时间"  v-model="model.createTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
                </a-form-model-item>

                <a-form-model-item label="整改截止时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rectifyEndTime">
                  <j-date placeholder="请选择整改截止时间"  v-model="model.rectifyEndTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
                </a-form-model-item>

                <a-form-model-item label="是否延期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDelay">
                  <a-select v-model="model.isDelay" placeholder="请选择是否延期">
                    <a-select-option value="0">是</a-select-option>
                    <a-select-option value="1">否</a-select-option>
                  </a-select>
                </a-form-model-item>

                <!--<a-form-model-item label="是否合格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isQualified">
                  <a-select v-model="model.isQualified" placeholder="请选择是否合格">
                    <a-select-option value="0">合格</a-select-option>
                    <a-select-option value="1">不合格</a-select-option>
                  </a-select>
                </a-form-model-item>-->

                <a-form-model-item label="是否需要整改" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isRectify">
                  <a-select v-model="model.isRectify" placeholder="请选择是否需要整改">
                    <a-select-option value="0">需要</a-select-option>
                    <a-select-option value="1">不需要</a-select-option>
                  </a-select>
                </a-form-model-item>

                <a-form-model-item label="整改内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rectifyContent">
                  <a-textarea
                    v-model:value="model.rectifyContent"
                    placeholder="请输入整改内容"
                    :auto-size="{ minRows: 2, maxRows: 7 }"
                  />
                </a-form-model-item>

                <a-form-model-item label="验收结果" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="acceptResult">
                  <a-select v-model="model.acceptResult" placeholder="请选择验收结果">
                    <a-select-option value="0">通过</a-select-option>
                    <a-select-option value="1">未通过</a-select-option>
                  </a-select>
                </a-form-model-item>

                <a-form-model-item label="上传图片" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="progressId">
                  <j-upload v-model="fileList" text="上传" fileType="image"></j-upload>
                </a-form-model-item>

                <a-form-model-item label="上传视频" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <j-upload v-model="videoFileList" text="上传" fileType="file"></j-upload>
                </a-form-model-item>

              </a-col>
            </a-row>
          </a-form-model>
        </j-form-container>
      </a-spin>
    </a-modal>
  </div>
</template>

<script>
  import {httpAction, getAction,getFileAccessHttpUrl} from '@/api/manage'

  export default {
    name: "addProjectAndAcceptModal",
    data(){
      return{
        fileList: [],
        videoFileList:[],
        width:'100%',
        model:{
        },
        previewTitle:'',
        title:'',
        acceptType: 0,
        customerId: 0,
        visible: false,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          createTime: [{ required: true, message: '验收时间不能为空' }],
          acceptResult: [{ required: true, message: '验收结果不能为空' }]
        },
        url: {
          add: "/ghCustomerProjectAndAccept/add",
        }
      }
    },
    created() {

    },
    methods:{
      handleCancel() {
        this.visible = false;
        this.fileList = [];
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }
            if (this.fileList.length > 0){
              this.model.imgUrl = this.fileList.toString();
            }
            if (this.videoFileList.length > 0){
              this.model.videoUrl = this.videoFileList.toString();
            }
            this.model.customerId = this.customerId;
            this.model.acceptType = this.acceptType;
            this.model.acceptTypeName = this.title;
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.model = {};
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              this.visible = false;
              this.fileList = [];
            })
          }
        })
      },
    }
  }
</script>

<style scoped>

</style>